{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. LC-3 Changes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Removed automatic %dump after assemble\n", "2. Removed GETC before prompt\n", "3. New Instructions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. New Instructions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The 16th instruction (1101) has now been implemented, and in fact, can be changed to be one of a couple of different meanings. By default it is SHIFT. \n", "\n", "**NOTE**: you can only use one MODE when you assemble a program." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2.1 SHIFT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```gas\n", "SHIFT SRC, SEXT-IMMEDIATE-BITS\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the default. SRC is a register to SHIFT, and SEXT-IMMEDIATE-BITS is the number (and direction) of bits to shift.\n", "\n", "Examples:\n", "\n", "```gas\n", "SHIFT R0, #1 ;; Shifts R0 1 bit to left\n", "SHIFT R1, #-2 ;; Shifts R1 2 bits to right\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2.1.1 Shift Left" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x3000\n", "AND R0, R0, 0\n", "ADD R0, R0, 1\n", "SHIFT R0, 1\n", "HALT\n", ".END" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 4\n", "Cycles: 27 (0.000013 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x0002 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3004 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2.1.2 Shift Right" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x3000\n", "AND R0, R0, 0\n", "ADD R0, R0, 2\n", "SHIFT R0, -1\n", "HALT\n", ".END" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 4\n", "Cycles: 27 (0.000013 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x0001 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3004 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2.2 TERMINAL" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instead of SHIFT, the 16th instruction can also be interpreted to be a TERMINAL command. TERMINAL takes a register containing the address of a string representing a terminal screen, and a immediate-mode value indicating whether the screen should be cleared." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "General form:\n", "\n", "```\n", ".SET MODE TERMINAL\n", "TERMINAL SRC, IMMEDIATE-CLEAR\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Examples:\n", "\n", "```gas\n", ".SET MODE TERMINAL\n", "TERMINAL R0, 1 ;; use string pointed to in R0 to print, clearing before hand\n", "TERMINAL R1, 0 ;; use string pointed to in R1 to print\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2.2.1 PUTS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The old way:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x3000\n", "LEA R0, DATA\n", "PUTS\n", "HALT\n", "DATA: .STRINGZ \"Hello, World!\\n\"\n", ".END" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, World!\n", "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 167\n", "Cycles: 1382 (0.000691 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x3003 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3003 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2.2.2 TERMINAL" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assembled! Use %dis or %dump to examine.\n" ] } ], "source": [ ".ORIG x3000\n", ".SET MODE TERMINAL\n", "LEA R0, DATA\n", "TERMINAL R0, 0\n", "TERMINAL R0, 0\n", "HALT\n", "DATA: .STRINGZ \"Hello, World!\"\n", ".END" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Hello, World!" ], "text/plain": [ "
Hello, World!" ], "text/plain": [ "
Hello, World!" ], "text/plain": [ "
+-----------------------------------------------------------------------------+\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "| |\n", "+-----------------------------------------------------------------------------+" ], "text/plain": [ "